<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
    <tr>
        <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0"
                   class="table_padding">
                <tr>
                    <td>
                        <table align="left">
                            <tr>
                                <td width="75px"><a class="button" id="select" href="javascript:void(0)"><span>查看明细</span></a>
                                </td>
                                <td width="50px"><a class="button" href="forwordPage?pagePath=role/add.jsp"><span>新增</span></a>
                                </td>
                                <td width="50px"><a class="button" onclick="deleteRole()" href="javascript:void(0);"><span>删除</span></a></td>
                                <td width="50px"><a class="button" href="forwordPage?pagePath=role/edit.jsp"><span>修改</span></a>
                                </td>
                                <td width="80px"><a class="button" onclick="distribute()" href="javascript:void(0)"><span>分配许可</span></a>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="25" height="26" align="right"></td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">
            <table border="0" cellpadding="0" cellspacing="0" id="box_num_table2"
                   class="box_num_table">
                <thead>
                <tr  bgcolor="white">
                    <td><input id="topCheck" type="checkbox" /></td>
                    <td>序号</td>
                    <td>代码</td>
                    <td>名称</td>
                    <td>描述</td>
                </tr>
                </thead>
                <from id="roleValue">
                <tbody id="role">
               <%-- <tr  bgcolor="white">
                    <td><input type="checkbox" /></td>
                    <td>1</td>
                    <td>001</td>
                    <td>管理员</td>
                    <td>&nbsp;</td>
                </tr>
                <tr  bgcolor="white">
                    <td><input type="checkbox" /></td>
                    <td>2</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>--%>
                </tbody>
                </from>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table border="0" cellpadding="0" cellspacing="0"
                   class="table_border">
                <tr>
                    <td>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0"
                               class="table_padding">
                            <tr>
                                <td width="8%" class="font_left">数据:120条</td>
                                <td width="12" class="font_left">第</td>
                                <td width="375" class="font_left">
                                    <input name="textfield2" type="text" size="2" maxlength="4" /> /5页
                                </td>
                                <td width="478" class="font_right">
                                    <a href="">首页</a>
                                    <a href="">上一页</a>
                                    <a href="">下一页</a>
                                    <a href="">末页</a>
                                    <a href="">刷新</a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script>

    $.post("getPage",{current:1,size:5},function (data) {
        $.each(data.records,function (a,b) {
            var str = '<tr  bgcolor="white">\n' +
                '                    <td><input id="bottomCheck" onclick="checkRole()" class="roleCheck" type="checkbox" value="'+b.id+'" /></td>\n' +
                '                    <td>'+a+'</td>\n' +
                '                    <td>'+b.code+'</td>\n' +
                '                    <td>'+b.name+'</td>\n' +
                '                    <td>'+b.remark+'</td>\n' +
                '                </tr>';
            $("#role").append(str);
        })
    })

    $("#select").click(function () {
        //获取所有选中的复选框
        let length = $(".roleCheck:checked").length;
        if(length==1){
            window.location.href = "geRole?id="+$(".roleCheck:checked").val();
        }else {
            alert("请选择一个角色！！")
        }
    })
    var flag = false;
    $("#topCheck").click(function () {
        let check = $(":checkbox[id!=topCheck]");
        check.prop("checked",this.checked);
    })
    function checkRole() {
        let a = $(":checkbox[id!=topCheck]:checked").length;
        let b = $(":checkbox[id!=topCheck]").length;
        //alert("选中："+a+" 全部："+b)
        $("#topCheck").prop("checked",a==b)
    }

    function deleteRole() {
        let checkbox = $(":checkbox[id!=topCheck]:checked");
        var ids = new Array();
        for (let i = 0; i < checkbox.length; i++) {
            ids.push(checkbox[i].value)
        }
        console.log(ids);
        $.post("deleteRole",{ids:ids},function (data) {
            console.log(data);
        });
    }
    function distribute() {
        //获取所有选中的复选框
        let length = $(".roleCheck:checked").length;
        if(length==1){
            window.location.href = "geRoleToAssign?id="+$(".roleCheck:checked").val();
        }else {
            alert("请选择一个角色！！")
        }
    }
</script>
